package com.godfrey.poi.pojo;

import lombok.Data;

/**
 * 矩形切割坐标
 *
 * @author godfrey
 * @since 2021-12-05
 */
@Data
public class RectangleCoordinate {

    /**
     * 矩形左上角经度
     */
    private double x0;

    /**
     * 矩形左上角纬度
     */
    private double y0;

    /**
     * 矩形右下角经度
     */
    private double x1;

    /**
     * 矩形右下角纬度
     */
    private double y1;

    public RectangleCoordinate(double x0, double y0, double x1, double y1) {
        this.x0 = x0;
        this.y0 = y0;
        this.x1 = x1;
        this.y1 = y1;
    }

    public RectangleCoordinate(String x0, String y0, String x1, String y1) {
        this.x0 = Double.parseDouble(x0);
        this.y0 = Double.parseDouble(y0);
        this.x1 = Double.parseDouble(x1);
        this.y1 = Double.parseDouble(y1);
    }

    /**
     * 获取矩形中心线的经度
     */
    public double getAverageX() {
        return (x0 + x1) / 2;
    }

    /**
     * 获取矩形中心线的纬度
     */
    public double getAverageY() {
        return (y0 + y1) / 2;
    }

    public String getPolygonString() {
        return x0 + "," + y0 + "|" + x1 + "," + y1;
    }
}